from dolfin import File
import os

class ConvDiffSolverBase():
    '''Base class for all solvers.'''
    def __init__(self):
        self.directory = 'results'
        if not os.path.exists(self.directory):
            os.mkdir(self.directory)

    def save(self,u,problem,name=None):
        '''Save the solution.'''
        if self.__class__.__name__ == 'ConvDiffSolverBase':
            raise TypeError('Call me from child classes only!')
        else:
            if name is None:
                out = File( '/'.join([self.directory, ('_'.join([problem.name, self.name]) + '.pvd')]) )
            else:
                out = File( '/'.join([self.directory, ('_'.join([problem.name, self.name,name]) + '.pvd')]) )
            out << u
